#include <iostream>
#include "main.h"
#include <stdint.h>
#include<string.h>
using namespace std;

std::string Member::GetName()
{
    // empty
}

MemberManager::MemberManager()
{
    // 没什么初始化内容
}

MemberManager::~MemberManager()
{
    // 没什么要析构
}

void MemberManager::AddMember()
{
    if (memberList.size() > 1000) {
        cout << "memberList size is more than 1000, can not enter member" << endl;
        return; 
    }

    Member member;
    cout << "please enter name:";
    cin >> member.name;

    cout << "please enter sex:";
    cin >> member.sex;

    cout << "please enter age:";
    cin >> member.age;

    cout << "please enter telenum:";
    cin >> member.teleNum;

    cout << "please enter addr:";
    cin >> member.addr;

    memberList.push_back(member);
}

void MemberManager::ShowMemberList()
{
    if (memberList.empty()) {
        cout << "memList is empty" << endl;
        return;
    }
    cout << "memberList成员列表如下：" << endl;
    vector<Member>::iterator it = memberList.begin();
    for (; it != memberList.end(); it++) {
        cout << it->name << " " << it->sex << " " << it->age << " ";
        cout << it->teleNum << " " << it->addr << endl;
    }
}

void MemberManager::ShowMember(const Member& member)
{
    cout << member.name << " " << member.sex << " " << member.age << " ";
    cout << member.teleNum << " " << member.addr << endl;
}

void MemberManager::FindMember(std::string name)
{
    if (memberList.empty()) {
        cout << "memberList is empty" << endl;
        return;
    }
    auto iter = memberList.begin();
    for(; iter != memberList.end();) {
        if (iter->GetName() == name) {
            cout << "find member name is " << name << endl;
        } else {
            iter++;
        }
    }
    cout << "can not find member name is " << name << endl;
}

void MemberManager::DelMember(std::string name)
{
    if (memberList.empty()) {
        cout << "memberList is empty" << endl;
        return;
    }
    auto iter = memberList.begin();
    for(; iter != memberList.end();) {
        if (iter->GetName() == name) {
            iter = memberList.erase(iter);
        } else {
            iter++;
        }
    }
    
}

void MemberManager::ClearMember()
{
    if (memberList.empty()) {
        cout << "memberList is empty" << endl;
        return;
    }
    memberList.clear();
}

void MemberManager::ModMember(std::string name, const int age)
{
    if (memberList.empty()) {
        cout << "memberList is empty" << endl;
        return;
    }
    for(auto& iter : memberList) {
        if (iter.GetName() == name) {
            iter.age = age;
            return;
        }
    }
    return;
}

void MemberManager::ShowMenu()
{
    cout << "***************************************" << endl;
    cout << "1、添加联系人" << endl;
    cout << "2、显示联系人" << endl;
    cout << "3、删除联系人" << endl;
    cout << "4、查找联系人" << endl;
    cout << "5、修改联系人" << endl;
    cout << "6、清空联系人" << endl;
    cout << "0、退出通讯录" << endl;
    cout << "****************************************" << endl;
    cout << "请输入你的选择：";

    uint32_t input;
    while(cin >> input) {
        switch(input) {
            case 0: {
                cout << "0、退出通讯录" << endl;
                break;
            }
            case 1: {
                AddMember();
                cout << "请输入接下来的操作:" << endl;
                continue;  
            }
            case 2: {
                ShowMemberList();
                cout << "请输入接下来的操作:" << endl;
                continue;
            }
            default: {
                cout << "不存在该选项,请输入接下来的操作:" <<endl;
                continue;
            }
        }
        break;
    }
}

int main()
{
    MemberManager MemberManager;
    MemberManager.ShowMenu();
    cout << "end" << endl;
    return 0;
}
